layui.config({
    version: true,   // 更新组件缓存，设为true不缓存，也可以设一个固定值
    base: 'assets/module/'
}).extend({
    steps: 'steps/steps',
    notice: 'notice/notice',
    cascader: 'cascader/cascader',
    dropdown: 'dropdown/dropdown',
    fileChoose: 'fileChoose/fileChoose',
    Split: 'Split/Split',
    Cropper: 'Cropper/Cropper',
    tagsInput: 'tagsInput/tagsInput',
    citypicker: 'city-picker/city-picker',
    introJs: 'introJs/introJs',
    zTree: 'zTree/zTree'
}).use(['layer', 'setter', 'index', 'admin', 'ax', 'mynotice'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var setter = layui.setter;
    var index = layui.index;
    var admin = layui.admin;
    var $ax = layui.ax;
    var mynotice = layui.mynotice;

    /* 检查是否登录 */
    if (!setter.getToken()) {
        return location.replace('/login.html');
    }

    /* 获取用户信息 */
    var ajax = new $ax("/getInfo", 'get', function (res) {
        setter.putUser(res.data);  // 缓存用户信息
        $('#havatar').attr('src', res.data.user.avatar);
        admin.renderPerm();  // 移除没有权限的元素
    }, function (res) {
        mynotice.error(res.msg);
    });
    ajax.start();


    /* 加载侧边栏 */
    var ajax = new $ax("/getRouters", 'get', function (res) {
    	index.regRouter([{
    	    name: '个人中心',
    	    url: '#/user/user-info'  // 路由关键字，必须要有#号
    	}]);
        index.regRouter(res.data);  // 注册路由
        index.renderSide(res.data);  // 渲染侧边栏
        // 加载主页
        index.loadHome({
            url: '#/console/workplace',
            name: '<i class="layui-icon layui-icon-home"></i>'
        });
    }, function (res) {
        mynotice.error(res.msg);
    });
    ajax.start();
});
